<template>
    <div class="test">
        <h2 >学校名称:{{name}}</h2>
        <h2>学校地址:{{address}}</h2>
    </div>
</template>

<script>
    import pubsub from 'pubsub-js'
    export default {
        name:'School',
        data() {
            return {
                name:'XXXssssaaa',
                address:'NJ'
            }
        },
        mounted(){
            //console.log('School',this.x.$on);
            //给x绑定事件hello，并通过匿名函数定义事件
            // this.$bus.$on('hello',(data)=>{
            //     console.log('我是School组件，我收到了数据：',data);
            // })

            this.puid = pubsub.subscribe('hello',(msgName,data)=>{
                console.log('有人发布hello消息，订阅成功',data);
                console.log(this);
            })
        },
        beforeDestroy(){
            // this.$bus.$off('hello')
            pubsub.unsubscribe(this.puid)
        }
    }
</script>

<style scoped>
    .test{
        background-color: orange;
        padding: 5px;
    }
</style>

<style scoped>

</style>
